{extend name="iframe" /}
{block name="body"}
<div class="layui-card" xmlns="http://www.w3.org/1999/html">
    <div style="width: 64%; float: left">
        <form action="{:url('admin/push/push')}" class="layui-form" method="post">
            <input type="hidden" id="user_id" name="user_id" value="{$data|default=''}" />
            <input type="hidden" id="projectRecommendId" name="projectRecommendId" value="{$projectRecommendId|default=''}" />
            <div class="layui-form-item">
                <label class="layui-form-label">消息模板选择</label>
                <div class="layui-input-block">
                    <select id="template" name="template" lay-filter="changeTxt">
                        <option value="5" {if condition="input('template') eq 5" }selected="selected"{/if}>自定义消息</option>
                        <option value="1" {if condition="input('template') eq 1" }selected="selected"{/if}>名片创建推送</option>
                        <option value="2" {if condition="input('template') eq 2" }selected="selected"{/if}>成果认领通知</option>
                        <option value="3" {if condition="input('template') eq 3" }selected="selected"{/if}>项目推送</option>
                        <option value="4" {if condition="input('template') eq 4" }selected="selected"{/if}>学者审核推送</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">推送渠道</label>
                <div class="layui-input-block">
                    <select name="channel">
                        <option value="1" {if condition="input('channel') eq 1" }selected="selected"{/if}>短信</option>
                        <option value="2" {if condition="input('channel') eq 2" }selected="selected"{/if}>邮件</option>
                        <option value="3" {if condition="input('channel') eq 3" }selected="selected"{/if}>短信+邮件</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">发送模式</label>
                <div class="layui-input-block">
                    <select name="type">
                        <option value="1" {if condition="input('type') eq 1" }selected="selected"{/if}>立即发送</option>
                        <option value="2" {if condition="input('type') eq 2" }selected="selected"{/if}>定时发送</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">发送时间</label>
                <div class="layui-input-block">
                    <input type="text" id="send_time" name="send_time" value="{$data.send_time|default=''}" autocomplete="off" placeholder="请输入发送时间" readonly class="layui-icon-date">
                </div>
            </div>
            <div id="checkRefuse" class="layui-form-item layui-hide">
                <label class="layui-form-label">审核不通过选项</label>
                <div class="layui-input-block">
                    <ul>
                        <input type="hidden" id="condition" name="condition" />
                        <li><input type="checkbox" lay-filter="changeCondition" name="conditionOpt" lay-skin="primary" value="邮箱" /><span>邮箱</span></li>
                        <li><input type="checkbox" lay-filter="changeCondition" name="conditionOpt" lay-skin="primary" value="电话" /><span>电话</span></li>
                        <li><input type="checkbox" lay-filter="changeCondition" name="conditionOpt" lay-skin="primary" value="机构" /><span>机构</span></li>
                    </ul>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">消息内容</label>
                <div class="layui-input-block">
                    <textarea id="content" name="content" autocomplete="off" placeholder="请输入消息内容" class="layui-textarea">{$data.content|default=''}</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-filter="i" lay-submit="">保存</button>
                    <button class="layui-btn layui-btn-primary" type="reset">重置</button>
                </div>
            </div>
        </form>
    </div>
    <div style="width: 35%; float: right">
        <div>
            预设参数
        </div>
        <div>
            <div style="width: 40%; float: left">
                {user}
            </div>
            <div style="width: 60%; float: right">
                用户姓名
            </div>
        </div>
        <div>
            <div style="width: 40%; float: left">
                {phone}
            </div>
            <div style="width: 60%; float: right">
                手机后4位尾号
            </div>
        </div>
        <div>
            <div style="width: 40%; float: left">
                {check}
            </div>
            <div style="width: 60%; float: right">
                审核不通过选项
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
    <script>
        $(function() {
            var template = $("#template").val();
            if (template === "4") {
                document.getElementById("content").value = "学者审核";
                $('#checkRefuse').removeClass('layui-hide');
            } else {
                $('#checkRefuse').addClass('layui-hide');
            }

            var projectRecommendId = $("#projectRecommendId").val();
            if (projectRecommendId !== null && projectRecommendId !== '') {
                document.getElementById("content").value = "项目推送";
            }
        });

        form.on('checkbox(changeCondition)', function(){
            var condition = [];
            $('.layui-form input[lay-skin="primary"]:checked').each(function (i) {
                condition[i] = $(this).val();
            });
            if (condition.length !== 0) {
                $("#condition").val(condition.join(","));
            }
        });

        laydate.render({
            elem: '#send_time',
            type: 'datetime'
        })

        form.on('select(changeTxt)', function(data){
            var msg = "";
            if (data.value === "1") {
                msg = "名片创建通知";
                $('#checkRefuse').addClass('layui-hide');
            } else if (data.value === "2") {
                msg = "成果认领通知";
                $('#checkRefuse').addClass('layui-hide');
            } else if (data.value === "3") {
                msg = "项目推送";
                $('#checkRefuse').addClass('layui-hide');
            } else if (data.value === "4") {
                msg = "学者审核";
                $('#checkRefuse').removeClass('layui-hide');
            } else if (data.value === "5") {
                msg = "";
                $('#checkRefuse').addClass('layui-hide');
            }
            document.getElementById("content").value = msg
        });
    </script>
{/block}
